<?php
import( 'tools.Setup.interfaces.SetupScreen' );
import( 'tools.Setup.classes.DatabaseSetupScreen' );
class DatabaseInstallScreen extends DatabaseSetupScreen implements SetupScreen
{
	public function handleAction( $action )
	{
		if( $action == "installDatabase" )
		{
			$this->connectDatabase( parse_ini_file( $this->config['sources']['db_access'] ) );

			$fileName	= $this->config['sources']['db_install'];
			if( !file_exists( $fileName ) )
				throw new Exception( "SQL Installation Script '".$fileName."' is not existing." );
			$lines	= file_get_contents( $fileName );
			$lines	= explode( ";\r", $lines );
			foreach( $lines as $line )
			{
				if( trim( $line ) )
					if( !$this->queryDatabase( $line ) )
						throw new Exception( "Installation went wrong at line \"".$line."\"." );
			}
			return true;
		}
	}

	public function getView()
	{
		$content	= require_once( $this->path."templates/".$this->name.".phpt" );
		return $content;	
	}
}
?>